package plp.imperative2.command;

import plp.expressions1.util.Tipo;
import plp.expressions2.expression.ExpUnaria;
import plp.expressions2.expression.Expressao;
import plp.expressions2.expression.Valor;
import plp.expressions2.memory.AmbienteCompilacao;
import plp.expressions2.memory.AmbienteExecucao;
import plp.expressions2.memory.VariavelJaDeclaradaException;
import plp.expressions2.memory.VariavelNaoDeclaradaException;
import plp.imperative2.memory.AmbienteExecucaoImperativa2;
import plp.imperative2.memory.ContextoExecucaoImperativa2;

public class ExpressaoOld extends ExpUnaria {

	public ExpressaoOld(Expressao expressao) {
		super(expressao, "old");
	}

	public Valor avaliar(AmbienteExecucao amb)
			throws VariavelNaoDeclaradaException, VariavelJaDeclaradaException {
		AmbienteExecucaoImperativa2 ambienteOld = ((ContextoExecucaoImperativa2) amb)
				.getContextoOld();

		if (ambienteOld != null)
			return getExp().avaliar(ambienteOld);
		else
			return getExp().avaliar(amb);

	}

	public boolean checaTipo(AmbienteCompilacao amb)
			throws VariavelNaoDeclaradaException, VariavelJaDeclaradaException {
		return getExp().checaTipo(amb);
	}

	protected boolean checaTipoElementoTerminal(AmbienteCompilacao amb)
			throws VariavelJaDeclaradaException, VariavelNaoDeclaradaException {
		return (getExp().getTipo(amb).eBooleano());
	}

	public Tipo getTipo(AmbienteCompilacao amb)
			throws VariavelNaoDeclaradaException, VariavelJaDeclaradaException {
		return getExp().getTipo(amb);
	}

}
